package easy

import (
	. "GoLeetcode/common"
)

/**
 * Definition for a Node.
 * type Node struct {
 *     Val int
 *     Children []*Node
 * }
 */

/*
TODO:如何使用迭代方法遍历?
 */

func preorder(root *Node) []int {
	result := make([]int, 0)
	var dfs func(node *Node)
	dfs = func(node *Node) {
		if node == nil {
			return
		}
		result = append(result, node.Val)
		for _, v := range node.Children {
			dfs(v)
		}
	}
	dfs(root)

	return result
}
